<script setup lang="ts">
  const props = withDefaults(
    defineProps<{
      width ?: string
    }>(),
    {
      width: '0px',
    },
  )

  // 注册多个事件，无需每次单独组成
  const emits = defineEmits(['close', 'setContent'])
  // const show: any = ref(false)
  onMounted(() => {
  })
  watch(() => props.width, (val) => {
    console.log(val, '宽度监听')
  })
  function drawerdel() {
    emits('close', Math.floor(Date.now() / 1000)) // 向父组件传递数据
  }
</script>

<template>
  <div class="css-drawer" :style="{ width }">
    <slot />
    <div class="drawerdel" :style="{ display: width === '0px' ? 'none' : '' }" @click="drawerdel()">
      <svg-icon name="ep:close" style="color: #999;" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
  .css-drawer {
    background-color: #fff;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    transition: width 0.5s ease;
    transition: height 0.5s ease;
    transition: all 0.5s;
    overflow: unset;
    box-shadow: var(--el-box-shadow-dark);
  }

  .drawerdel {
    width: 20px;
    height: 35px;
    background-color: #fff;
    position: absolute;
    top: 8px;
    left: -20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px 0 0 8px;
    z-index: 9999;
    box-shadow: var(--el-box-shadow-dark);
    cursor: pointer;
  }
</style>
